from Common.MTurk.BaseParams import BaseParams

class CreateExternalHITParams(BaseParams):
    """
        Data Module for create HIT request
    """
    
    # default value for non-required parameters is None
    # default value for required parameters must be some value except None is default value in MTurk API
    def __init__(self, question, lifetimeInSeconds=259200, maxAssignments=1, requesterAnnotation="", hitTypeID='', 
                 title='Test HIT Creation', description='This is a default value for HIT creation request', 
                 reward={'Amount':0.01, 'CurrencyCode':'USD'}, 
                 assignmentDurationIn=3600, keywords=None, autoApprovalDelayInSeconds=86400, qualificationRequirement=None):
        BaseParams.__init__(self, 'CreateHIT') #operation
        
        self.parameters["Question"]=question
        self.parameters["LifetimeInSeconds"]=lifetimeInSeconds # any integer between 30 (30 seconds) and 31536000 (365 days).
        self.parameters["MaxAssignments"]=maxAssignments # any integer between 1 and 1000000000 (1 billion).
            
        if '' != requesterAnnotation:
            self.parameters['RequesterAnnotation']=requesterAnnotation # must not be longer than 255 characters
            
        
        if '' != hitTypeID:
            # create HIT with HIT Type Id
            self.parameters['HITTypeId'] = hitTypeID
        else:
            # create HIT without HIT Type Id
            self.parameters['Title'] = title # must not be more than 128 characters
            self.parameters['Description'] = description # cannot be more than 2,000 characters in length
            self.parameters['AssignmentDurationInSeconds'] = assignmentDurationIn # any integer between 30 (30 seconds) and 31536000 (365 days)
            if None != keywords:
                self.parameters['Keywords'] = keywords
            self.parameters['AutoApprovalDelayInSeconds'] = autoApprovalDelayInSeconds
            self.parameters['Reward.1.Amount'] = reward["Amount"]
            self.parameters['Reward.1.CurrencyCode'] = reward["CurrencyCode"]

if __name__ == "__main__":
    chp = CreateExternalHITParams(title="Answer a question", 
                                  description="Please provide a short answer to this question.",
                                  keywords="hello, world, command, sample, question, answer",
                                  reward={'Amount':0.02, 'CurrencyCode':'USD'},
                                  maxAssignments=1,
                                  lifetimeInSeconds=259200,
                                  assignmentDurationIn=3600,
                                  question='<ExternalQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionForm.xsd"><ExternalURL>http://tictactoe.amazon.com/gamesurvey.cgi?gameid=01523</ExternalURL><FrameHeight>400</FrameHeight></ExternalQuestion>')
    print chp.parameters


"""
<HIT>
  <HITId>123RVWYBAZW00EXAMPLE</HITId>
  <HITTypeId>T100CN9P324W00EXAMPLE</HITTypeId>
  <CreationTime>2005-06-30T23:59:59</CreationTime>
  <HITStatus>Assignable</HITStatus>
  <MaxAssignments>5</MaxAssignments>
  <AutoApprovalDelayInSeconds>86400</AutoApprovalDelayInSeconds>
  <LifetimeInSeconds>86400</LifetimeInSeconds>
  <AssignmentDurationInSeconds>300</AssignmentDurationInSeconds>
  <Reward>
    <Amount>25</Amount>
    <CurrencyCode>USD</CurrencyCode>
    <FormattedPrice>$0.25</FormattedPrice>
  </Reward>
  <Title>Location and Photograph Identification</Title>
  <Description>Select the image that best represents...</Description>
  <Keywords>location, photograph, image, identification, opinion</Keywords>
  <Question>
    &lt;QuestionForm&gt;
      [XML-encoded Question data]
    &lt;/QuestionForm&gt;
  </Question>
  <QualificationRequirement>
    <QualificationTypeId>789RVWYBAZW00EXAMPLE</QualificationTypeId>
    <Comparator>GreaterThan</Comparator>
    <Value>18</Value>
  </QualificationRequirement>
  <HITReviewStatus>NotReviewed</HITReviewStatus>
</HIT>
"""